<?php

namespace App\Services\MakeMoment;

use App\Models\User;
use App\Models\Moment;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;

class MakeMoment
{
	protected $user;
	
	protected $content = null;
	protected $images = [];
	
	public function __construct(User $user, $content, $images = [])
	{
		$this->user = $user;
		$this->content = $content;
		$this->images = $images;
	}
	
	protected function createMoment()
	{
		$data = [
			'content' => $this->content,
			'images' => $this->images
		];
		return $this->user->moments()->create($data);
	}
	
	
	
	protected function create()
	{
		$moment = DB::transaction(function () {
			
			$moment = $this->createMoment();
			
			Log::debug("new moment: {$moment->id}");
			
			return $moment;
		});
		
		return $moment;
	}
	
	public function make()
	{
		return $this->create();
	}
}
